package com.appkubes.portal.admin.application.app.admin.controller;

import com.appkubes.common.Response;
import com.appkubes.portal.admin.application.app.admin.entity.vo.AdminRoleAddVO;
import com.appkubes.portal.admin.application.auth.service.KeyCloakRoleService;
import com.appkubes.cloud.config.params.paramValid.ParamValid;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "管理员角色模块")
@RestController
@RequestMapping("/app/admin/role")
public class AppAdminRoleController {
    @Resource
    KeyCloakRoleService keyCloakRoleService;

    @ApiOperation("获取管理员角色列表")
    @GetMapping("/get/{adminKey}")
    public Response get(@PathVariable("adminKey") String adminKey) {
        List<?> list = keyCloakRoleService.getUserClientRoleList(adminKey);
        return Response.success(list);
    }

    @ApiOperation("保存管理员角色")
    @PostMapping("/add")
    public Response add(@ParamValid AdminRoleAddVO adminRoleAddVO) {
        keyCloakRoleService.addRoleToUser(adminRoleAddVO.getAdminKey(), adminRoleAddVO.getRoleName());
        return Response.success();
    }

    @ApiOperation("保存管理员角色")
    @PostMapping("/remove")
    public Response remove(@ParamValid AdminRoleAddVO adminRoleAddVO) {
        keyCloakRoleService.removeRoleFromUser(adminRoleAddVO.getAdminKey(), adminRoleAddVO.getRoleName());
        return Response.success();
    }

}
